using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BaseMap : MonoBehaviour
{
    private GameObject MapImage;

    private GameObject Highlight;

    private Color HighlightColor;

    private bool HighlightVisible;
    // Start is called before the first frame update
    private void Awake()
    {
        MapImage = this.transform.Find("MapImage").gameObject;
        Highlight = this.transform.Find("Highlight").gameObject;
    }

    /// <summary>
    /// 设置是否显示高亮
    /// </summary>
    /// <param name="isVisible"></param>
    public void SetHighlightVisible(bool isVisible)
    {
        Highlight.transform.localScale = isVisible ? new Vector3(1,1,1): new Vector3(0,0,0);
    }
    
    /// <summary>
    /// 设置高亮的颜色
    /// </summary>
    /// <param name="color"></param>
    public void SetHighlightColor(Color color)
    {
        Highlight.GetComponent<SpriteRenderer>().color = color;
    }
    
    public void InitShow()
    {
        HighlightColor = Color.yellow;
        HighlightVisible = false;
    }

    private void Update()
    {
        InitShow();

        if (GameState.ShowMoveMapDict != null && GameState.ShowMoveMapDict.ContainsKey(this.transform))
        {
            HighlightVisible = true;
            HighlightColor = Color.green; 
        }
        
        if (GameState.AttackRangeDict != null && GameState.AttackRangeDict.ContainsKey(this.transform) == this.transform)
        {
            HighlightVisible = true;
            HighlightColor = Color.red;
        }
        
        if (GameState.FocusMapTransform == this.transform)
        {
            HighlightVisible = true;
            HighlightColor = Color.blue;
        }
        
        SetHighlightColor(HighlightColor); 
        SetHighlightVisible(HighlightVisible);
    }
}
